//  Copyright Druid Mechanics


#include "AbilitySystem/ModMagCalc/MMC_MaxHealth.h"
#include "AbilitySystem/AuraAttributeSet.h"
#include "Interaction/CombatInterface.h"

UMMC_MaxHealth::UMMC_MaxHealth()
{
	/**
	 * AttributeToCapture: 被捕获的GA。
	 */
	VigorDef.AttributeToCapture = UAuraAttributeSet::GetVigorAttribute();
	/**
	 * AttributeSource: 被捕获GA的来源。
	 */
	VigorDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target;
	VigorDef.bSnapshot = false;

	/**
	 * RelevantAttributesToCapture: 被捕获的与计算相关的GA。
	 */
	RelevantAttributesToCapture.Add(VigorDef);
}

float UMMC_MaxHealth::CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const
{
	/**
	 * CapturedSourceTags: GESpec被创建时捕获的源(Source)标签。
	 * GetAggregatedTags: 返回Spec和Actor标签的合并。
	 */
	const FGameplayTagContainer* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags();
	/**
	 * CapturedTargetTags: 返回执行期间捕获的目标(Target)的标签。
	 */
	const FGameplayTagContainer* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags();
	/**
	 * FAggregatorEvaluateParameters: 从调用者/游戏代码传递的被用于整合评估的数据。
	 */
	FAggregatorEvaluateParameters EvaluateParameters;
	EvaluateParameters.SourceTags = SourceTags;
	EvaluateParameters.TargetTags = TargetTags;

	float Vigor = 0.f;
	/**
	 * GetCapturedAttributeMagnitude: 在一个巨量运算调用期间获取属性巨量的便利方法。
	 */
	GetCapturedAttributeMagnitude(VigorDef, Spec, EvaluateParameters, Vigor);
	Vigor = FMath::Max<float>(Vigor, 0.f);
	
	int32 PlayerLevel = 1;
	if(Spec.GetContext().GetSourceObject()->Implements<UCombatInterface>())
	{
		PlayerLevel = ICombatInterface::Execute_GetPlayerLevel(Spec.GetContext().GetSourceObject());
	}
	return 80.f + 2.5f * Vigor + 10.f * PlayerLevel;
}
